Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

regression: Fix property expansion of "recipe.preproc.macros" #2268

Merged
merged 1 commit into from
Aug 18, 2023

Conversation

cmaglie
Copy link
Member

@cmaglie cmaglie commented Aug 17, 2023

Please check if the PR fulfills these requirements

See how to contribute

  • The PR has no duplicates (please search among the Pull Requests
    before creating one)
  • The PR follows
    our contributing guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)
  • UPGRADING.md has been updated with a migration guide (for breaking changes)
  • configuration.schema.json updated if new parameters are added.

What kind of change does this PR introduce?

Previously the undefined template placeholders in recipe.preproc.macros were silently replaced by the empty string. This changed after a refactoring in 0585435.

Previously it was:

0585435#diff-371f93465ca5a66f01cbe876348f67990750091d27a827781c8633456b93ef3bL62

-       cmd, err := builder_utils.PrepareCommandForRecipe(buildProperties, "recipe.preproc.macros", true, ctx.PackageManager.GetEnvVarsForSpawnedProcess())

The true parameter in the call to builder_utils.PrepareCommandForRecipe is the parameter removeUnsetProperties.

This behavior has not been ported over after the "refactoring": 0585435#diff-733dda6759fe968eb8a8d7305c37c7a320a8df52764ca0cba8e88a6f1d077eb5R44-R65

+       const gccPreprocRecipeProperty = "recipe.preproc.macros"
+       if gccBuildProperties.Get(gccPreprocRecipeProperty) == "" {
+               // autogenerate preprocess macros recipe from compile recipe
+               preprocPattern := gccBuildProperties.Get("recipe.cpp.o.pattern")
+               // add {preproc.macros.flags} to {compiler.cpp.flags}
+               preprocPattern = strings.Replace(preprocPattern, "{compiler.cpp.flags}", "{compiler.cpp.flags} {preproc.macros.flags}", 1)
+               // replace "{object_file}" with "{preprocessed_file_path}"
+               preprocPattern = strings.Replace(preprocPattern, "{object_file}", "{preprocessed_file_path}", 1)
+
+               gccBuildProperties.Set(gccPreprocRecipeProperty, preprocPattern)
+       }
+
+       pattern := gccBuildProperties.Get(gccPreprocRecipeProperty)
+       if pattern == "" {
+               return nil, nil, errors.Errorf(tr("%s pattern is missing"), gccPreprocRecipeProperty)
+       }
+
+       commandLine := gccBuildProperties.ExpandPropsInString(pattern)
+       args, err := properties.SplitQuotedString(commandLine, `"'`, false)
+       if err != nil {
+               return nil, nil, err
+       }

that is completely missing the call to properties.DeleteUnexpandedPropsFromString.

What is the current behavior?

The old behavior for property expansion of "recipe.preproc.macros" is not preserved. See #2267 for details.

What is the new behavior?

The old behavior for property expansion of "recipe.preproc.macros" is restored.

Does this PR introduce a breaking change, and is titled accordingly?

No

Other information

The regression has been introduced in #2194.
Fix #2261

Previously the undefined template placeholders in "recipe.preproc.macros"
were silently replaced the empty string. This changed after a
refactoring in 0585435.

Previously it was:

arduino@0585435#diff-371f93465ca5a66f01cbe876348f67990750091d27a827781c8633456b93ef3bL62
-       cmd, err := builder_utils.PrepareCommandForRecipe(buildProperties, "recipe.preproc.macros", true, ctx.PackageManager.GetEnvVarsForSpawnedProcess())

The `true` parameter in the call to `builder_utils.PrepareCommandForRecipe` is the parameter `removeUnsetProperties`.

This behaviour has not been ported over after the "refactoring":
arduino@0585435#diff-733dda6759fe968eb8a8d7305c37c7a320a8df52764ca0cba8e88a6f1d077eb5R44-R65

+       const gccPreprocRecipeProperty = "recipe.preproc.macros"
+       if gccBuildProperties.Get(gccPreprocRecipeProperty) == "" {
+               // autogenerate preprocess macros recipe from compile recipe
+               preprocPattern := gccBuildProperties.Get("recipe.cpp.o.pattern")
+               // add {preproc.macros.flags} to {compiler.cpp.flags}
+               preprocPattern = strings.Replace(preprocPattern, "{compiler.cpp.flags}", "{compiler.cpp.flags} {preproc.macros.flags}", 1)
+               // replace "{object_file}" with "{preprocessed_file_path}"
+               preprocPattern = strings.Replace(preprocPattern, "{object_file}", "{preprocessed_file_path}", 1)
+
+               gccBuildProperties.Set(gccPreprocRecipeProperty, preprocPattern)
+       }
+
+       pattern := gccBuildProperties.Get(gccPreprocRecipeProperty)
+       if pattern == "" {
+               return nil, nil, errors.Errorf(tr("%s pattern is missing"), gccPreprocRecipeProperty)
+       }
+
+       commandLine := gccBuildProperties.ExpandPropsInString(pattern)
+       args, err := properties.SplitQuotedString(commandLine, `"'`, false)
+       if err != nil {
+               return nil, nil, err
+       }

that is missing the call to `properties.DeleteUnexpandedPropsFromString`.
@cmaglie cmaglie added priority: high Resolution is a high priority topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project criticality: highest Of highest impact topic: build-process Related to the sketch build process labels Aug 17, 2023
@cmaglie cmaglie added this to the Arduino CLI 0.34.0 milestone Aug 17, 2023
@cmaglie cmaglie self-assigned this Aug 17, 2023
@codecov
Copy link

codecov bot commented Aug 17, 2023

Codecov Report

Patch coverage: 100.00% and no project coverage change.

Comparison is base (9510d61) 62.95% compared to head (4212ad1) 62.95%.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #2268   +/-   ##
=======================================
  Coverage   62.95%   62.95%           
=======================================
  Files         220      220           
  Lines       19546    19547    +1     
=======================================
+ Hits        12305    12306    +1     
  Misses       6151     6151           
  Partials     1090     1090           
Flag Coverage Δ
unit 62.95% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Changed Coverage Δ
arduino/builder/preprocessor/gcc.go 79.54% <100.00%> (+0.47%) ⬆️

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@cmaglie cmaglie merged commit 3bd60c6 into arduino:master Aug 18, 2023
89 checks passed
@cmaglie cmaglie deleted the fix_regression_2 branch August 18, 2023 07:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
criticality: highest Of highest impact priority: high Resolution is a high priority topic: build-process Related to the sketch build process topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unexpanded properties no longer deleted from recipe.preproc.macros
2 participants